package com.portal.business.helps;

import java.util.ArrayList;
import java.util.List;

import com.portal.business.helps.dao.HelpsDao;
import com.portal.business.helps.dto.HelpsDTO;
import com.portal.business.helps.dto.PortalResultBean;
import com.portal.framework.common.PortalSearchBean;
import com.portal.framework.page.Pager;
/**
 * 
 * 项目名称: Portal     
 * 类名称:   HelpsServiceImpl     
 * 类描述:   帮助模块 
 * 创建人:   骆海东
 * 创建时间: Aug 29, 2011 4:57:50 PM     
 * 最后修改人:   骆海东
 * 最后修改时间: Aug 29, 2011 4:57:50 PM     
 * 最后修改备注:
 */
public class HelpsServiceImpl implements HelpsService {
	
    private HelpsDao helpsDao;

	public HelpsDao getHelpsDao() {
		return helpsDao;
	}

	public void setHelpsDao(HelpsDao helpsDao) {
		this.helpsDao = helpsDao;
	}

	public HelpsDTO addHelps(HelpsDTO helpsDTO) {
		return this.helpsDao.create(helpsDTO);
	}

	public int delHelps(Integer helpsId) {
		return this.helpsDao.delete(helpsId);
	}

	public int delHelpsBatch(String[] asIdsStr) {
		int len=asIdsStr.length;
		Integer[] ids=new Integer[len];
		for (int i = 0; i <len; i++) {
			ids[i]=Integer.valueOf(asIdsStr[i]);
		}
		return this.helpsDao.deleteBatch(ids);
	}

	public HelpsDTO findByID(Integer helpsId) {
		return this.helpsDao.findById(helpsId);
	}

	public HelpsDTO updateHelps(HelpsDTO helpsDTO) {
		return this.helpsDao.update(helpsDTO);
	}

	public PortalResultBean findHelps(PortalSearchBean portalSearchBean) {
		
		String hql="from HelpsDTO ";
		String countHql="select count(helpId) ";
		//用于保存查找输入参数集合
		List<Object> osList=new ArrayList<Object>();
		if(portalSearchBean.getName()!=null&&!portalSearchBean.getName().trim().equals("")){
			hql=hql+"where helpTitle like ?";
			osList.add("%"+portalSearchBean.getName()+"%");
		}
		hql=hql+" order by helpId desc";
		//获取总数
		int count=this.helpsDao.countQuery(countHql+hql,osList.toArray());
		//设置页码对象
		Pager pager=new Pager();
		pager.setPageSize(portalSearchBean.getPageSize());
		pager.setTotal(count);
		pager.setCurrentPage(portalSearchBean.getPage());
		//获取数据
		List<HelpsDTO> olsit=this.helpsDao.find(pager.getStart(),pager.getPageSize(), HelpsDTO.class, hql, osList.toArray());
		//设置返回对象
		PortalResultBean pb=new PortalResultBean();
		pb.setCount(count);
		pb.setResultList(olsit);
		return pb;
	}

	
	public List<HelpsDTO> findIndex() {
		String hql="from HelpsDTO order by helpId desc";
		return this.helpsDao.find(0, 8, hql);
	}

	
}

		